﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Maniac
{
    class HistoricalPriceSorter
    {
        private HistoricalPriceSorter()
        {
        }
        public static int InitializeSort(HistoricalPrice x, HistoricalPrice y)
        {
            int tviReturn = 0;
            if (x == null)
            {
                if (y == null)
                {
                    tviReturn = 0;
                }
                else
                {
                    tviReturn = -1;
                }
            }
            else
            {
                if (y == null)
                {
                    tviReturn = 1;
                }
            }
            return tviReturn;
        }
        public static int SortPricesByGainPriorClose(HistoricalPrice x, HistoricalPrice y)
        {
            int tviReturn = 0;
            tviReturn = InitializeSort(x, y);
            if ((tviReturn == 0) && (x != null) && (y != null))
            {
                if (x.GainPriorClose > y.GainPriorClose)
                    tviReturn= - 1;
                if (x.GainPriorClose == y.GainPriorClose)
                    tviReturn= 0;
                if (x.GainPriorClose < y.GainPriorClose)
                    tviReturn= 1;
            }
            return tviReturn;
        }
        public static int SortPricesByGainPercentPriorClose(HistoricalPrice x, HistoricalPrice y)
        {
            int tviReturn = 0;
            tviReturn = InitializeSort(x, y);
            if ((tviReturn == 0) && (x != null) && (y != null))
            {
                if (x.GainPriorClosePercent > y.GainPriorClosePercent)
                    tviReturn= - 1;
                if (x.GainPriorClosePercent == y.GainPriorClosePercent)
                    tviReturn= 0;
                if (x.GainPriorClosePercent < y.GainPriorClosePercent)
                    tviReturn= 1;
            }
            return tviReturn;
        }
        public static int SortPricesByDateDescending(HistoricalPrice x, HistoricalPrice y)
        {
            int tviReturn = 0;
            tviReturn = InitializeSort(x, y);
            if ((tviReturn == 0) && (x != null) && (y != null))
            {
                tviReturn = y.Date.CompareTo(x.Date);
            }
            return tviReturn;
        }
    }
}
